import { getUser } from "../../api/sop";
import { err, to, toast } from "../../utils/wxapi";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    publisher: false,
    user: {},
    nav: [
      // {
      //   img: "../../images/my/my_nav1.png",
      //   title: "我的补贴卡",
      //   url: "/two/pages/subsidy/subsidy",
      // },
      // {
      //   img: "../../images/my/my_nav2.png",
      //   title: "实名认证",
      //   url: "/two/pages/userId/userId",
      // },
      {
        img: "../../images/my/my_nav3.png",
        title: "收藏",
        url: "/two/sc/sc",
      },
      {
        img: "../../images/my/my_nav4.png",
        title: "浏览",
        url: "/two/ll/ll",
      },
    ],
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.user();
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2,
      });
    }
  },
  async user() {
    try {
      const res = await getUser();
      if (res.respCode === 200) {
        const user = JSON.parse(res.source);
        console.log(user);
        wx.setStorageSync("user", user);
        this.setData({ user });
      }
    } catch (error) {
      err(error);
      throw error;
    }
  },
  tonav(e) {
    const { url } = e.currentTarget.dataset;
    to(url);
  },

  gotoset() {
    to("/two/pages/set/set");
  },
  toentry() {
    to("/two/entry/entry");
  },
  gotx() {
    to("/two/tx/tx");
  },
  toastuser() {
    toast("已完成实名认证");
  },
  goID() {
    to("/two/pages/userId/userId");
  },
  goShop() {
    to("/two/pages/atPresent/atPresent?status=3");
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
